Skip to content

feat: add commitBehavior to NumberField#9679

Merged
snowystinger merged 6 commits intoadobe:mainfrom
will-stone:add-value-snapping-disabled-to-number-field
Mar 17, 2026
Merged

feat: add commitBehavior to NumberField#9679
snowystinger merged 6 commits intoadobe:mainfrom
will-stone:add-value-snapping-disabled-to-number-field

Conversation

@will-stone
Copy link
Contributor

@will-stone will-stone commented Feb 18, 2026

As discussed here: #8776

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

  1. Open the Step3WithMin2Max21ValueSnappingDisabled story.
  2. Enter a value that's either under min, over max, or a wrong step.
  3. Blur the input.
  4. Notice the onChange callback fires with the same value you entered, and the input does not auto-snap to a valid number.

🧢 Your Project:

This will be used in an e-commerce situation where the NumberField is used for product quantity. Snapping is dangerous, for us, because a customer may not know that the number has been auto-healed, causing them to order less or more of what they need. I work for RS Group, and RAC powers our component library: ion. The component in question isn't live yet, but the RAC implementation is to replace our QuantityStepper component.

@will-stone
Copy link
Contributor Author

Happy to have a stab at the docs but I'd like to please know if this is something you'd consider adding first 🙏 😅

@LFDanLu
Copy link
Member

LFDanLu commented Feb 20, 2026

@will-stone interesting, this went a bit of a different route than I was expecting but I suppose native number type input fields do behave the same way. @snowystinger Any opinions here? Do you remember any reasons we didn't go this route in the first place?

@will-stone
Copy link
Contributor Author

Hi 👋 🙂 Anything I can do to advance this? If you're happy with the name then I can have a crack at the docs.

@LFDanLu
Copy link
Member

LFDanLu commented Mar 10, 2026

@will-stone sorry about the delay, I'll take a look soon. I hadn't realized the team had already discussed this a while back haha, I'll take a look at overall behavior soon. Definitely feel free to take a crack at the docs, the team can help out with those if behavior needs to be refactored/naming gets changed/etc

/**
* Disables value snapping when user finishes editing the value (e.g. on blur).
*/
isValueSnappingDisabled?: boolean
Copy link
Member

@snowystinger snowystinger Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such a long prop name, how would we feel instead about, question to the team
isSnapDisabled

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that shorter name is fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps interactOutside behavior related? like RangeCalendar? and DatePicker?
See #8899 (review) as well

expect(onChangeSpy).toHaveBeenCalledWith(5);
expect(textField).toHaveAttribute('value', '5');

expect(container).not.toHaveAttribute('aria-invalid');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe in the v3 spectrum component this should be false, but if we write the same test in the react aria component, does it have the invalid attribute? seems like it should

/**
* Disables value snapping when user finishes editing the value (e.g. on blur).
*/
isValueSnappingDisabled?: boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that shorter name is fine

@snowystinger snowystinger marked this pull request as ready for review March 14, 2026 06:02
snowystinger
snowystinger previously approved these changes Mar 14, 2026
@snowystinger snowystinger changed the title feat: add isValueSnappingDisabled to NumberField feat: add interactOutsideBehavior to NumberField Mar 16, 2026
LFDanLu
LFDanLu previously approved these changes Mar 16, 2026
@devongovett devongovett dismissed stale reviews from LFDanLu and snowystinger via 1cb6081 March 17, 2026 19:15
@github-actions github-actions bot added the S2 label Mar 17, 2026
@snowystinger snowystinger changed the title feat: add interactOutsideBehavior to NumberField feat: add commitBehavior to NumberField Mar 17, 2026
snowystinger
snowystinger previously approved these changes Mar 17, 2026
Comment on lines +210 to +214
export const InteractOutsideBehaviorNone: NumberFieldStory = () => render({step: 3, minValue: 2, maxValue: 21, commitBehavior: 'validate'});

InteractOutsideBehaviorNone.story = {
name: 'commitBehavior = validate'
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const InteractOutsideBehaviorNone: NumberFieldStory = () => render({step: 3, minValue: 2, maxValue: 21, commitBehavior: 'validate'});
InteractOutsideBehaviorNone.story = {
name: 'commitBehavior = validate'
};
export const CommitBehaviorValidate: NumberFieldStory = () => render({step: 3, minValue: 2, maxValue: 21, commitBehavior: 'validate'});
CommitBehaviorValidate.story = {
name: 'commitBehavior = validate'
};

LFDanLu
LFDanLu previously approved these changes Mar 17, 2026
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the validation behavior except for the native localizations since Chrome on Mac can't override the display language, will test that on Windows later

@LFDanLu LFDanLu dismissed stale reviews from snowystinger and themself via c0dbdbf March 17, 2026 20:31
@snowystinger snowystinger enabled auto-merge March 17, 2026 20:34
@snowystinger snowystinger added this pull request to the merge queue Mar 17, 2026
Merged via the queue into adobe:main with commit f187e3b Mar 17, 2026
28 checks passed
@will-stone will-stone deleted the add-value-snapping-disabled-to-number-field branch March 17, 2026 20:50
@will-stone
Copy link
Contributor Author

Thank you everyone! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants